package com.lfg.leetcode.leetcode0;

public class No21MergeTwoLists {

    public static ListNode mergeTwoLists(ListNode l1, ListNode l2) {
        if (l1 == null) {
            return l2;
        }
        if (l2 == null) {
            return l1;
        }
        ListNode ret = new ListNode(1);
        ListNode node = ret;
        while (l1 != null && l2 != null) {
            if (l1.val <= l2.val) {
                node.next = l1;
                node = node.next;
                l1 = l1.next;
            } else {
                node.next = l2;
                node = node.next;
                l2 = l2.next;
            }

        }
        if (null != l1) {
            node.next = l1;
        }
        if (null != l2) {
            node.next = l2;
        }
        return ret.next;
    }


    public static void main(String[] args) {
        System.out.println(mergeTwoLists(ListNode.deserialize("[]"), ListNode.deserialize("[1]")).val);
//        System.out.println(threeSum(new int[]{-2,0,0,2,2}));
    }
}
